#ifndef VISION_LOCATION_H
#define VISION_LOCATION_H

#include "../sccamera.h"
#include "../scvision.h"
#include "Calibration/pixel2mech.h"
#include "errorHandling/silicolerrorhandler.h"
#include "scvision_global.h"
#include "visionlocationconfig.h"
#include <QtConcurrent>

class SCVISIONSHARED_EXPORT VisionLocation : public QObject
{
    Q_OBJECT
public:
    VisionLocation(SCVision *vision, SCCamera *m_camera, VisionLocationConfig *config);

    void setMapping(Pixel2Mech *mapping);

    bool performPR(PrOffset &offset, int roiRowIndex = 0, int roiColIndex = 0);

    void startContinuallyPerformPr();

    void stopContinuallyPerformPr();

    bool performPR(PRResultStruct &prResult, int roiRowIndex = 0, int roiColIndex = 0);

    bool performPR(QImage& image, PRResultStruct &prResult, int roiRowIndex = 0, int roiColIndex = 0);

    void openLight();

    void closeLight();

    QImage getImage();

    bool performPR(QImage image, PrOffset &offset, bool showImage, int roiRowIndex = 0, int roiColIndex = 0);

    bool result2Offset(PRResultStruct &prResult, PrOffset &prOffset);

    SCCamera *camera() const;

    void tryShowImage(QImage &image);

private slots:
    void onVisionLocationConfigLightBrightnessChanged(int lightBrightnessChanged);
    void onVisionLocationConfigSecondLightBrightnessChanged(int lightBrightnessChanged);

private:
    QString prFileName() const;
    void saveShowResultImage(QImage &image, PRResultImageInfo &prResultImageInfo, bool showImage = true);

private:
    bool isContinuallyPerformPr = false;
    SCVision *vision;
    SCCamera *m_camera;
    VisionLocationConfig *m_config;
    Pixel2Mech *mapping;
};

#endif    // VISION_LOCATION_H
